package com.lrj.mysecurity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lrj.mysecurity.dao.UserRoleDao;
import com.lrj.mysecurity.entity.UserRole;
import com.lrj.mysecurity.entity.UserRoleConstant;
import com.lrj.mysecurity.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserRoleServiceImpl implements UserRoleService {
    @Autowired
    private UserRoleDao userRoleDao;


    @Override
    public List<Long> getRoleIdListByUserId(Long userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(UserRoleConstant.COLUMN_USER_ID, userId);
        List<UserRole> userRoleList = userRoleDao.selectList(queryWrapper);

        List<Long> roleIdList = userRoleList.stream().map(userRole -> userRole.getRoleId()).collect(Collectors.toList());
        return roleIdList;
    }
}
